﻿using AutoMapper;
using MediatR;
using S.EarTag.API.Mediator.MediatorCommand.MarkCommand;
using S.EarTag.Domain.Model;
using S.EarTag.Infrastructure.Repository.Interface.IEarTagRepository;

namespace S.EarTag.API.Mediator.MediatorCommandHandler.MarkCommandHandler
{
    public class MarkUpdateCommandHandler : IRequestHandler<MarkUpdateCommand, bool>
    {
        private readonly IMarkModelRepository _markModelRepository;
        private readonly IMapper _mapper;
        public MarkUpdateCommandHandler(IMarkModelRepository markModelRepository, IMapper mapper)
        {
            _markModelRepository = markModelRepository;
            _mapper = mapper;
        }
        /// <summary>
        /// 修改戴标数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(MarkUpdateCommand request, CancellationToken cancellationToken)
        {
            return await _markModelRepository.UpdateAsync(_mapper.Map<MarkModel>(request));
        }
    }
}
